home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program is a smoothing-type algorithm which computes Pascal's
- * triangle, to size M x N, by seting each element to the sum of the numbers
- * directly above and to the left. It illustrates user-defined mappings. */
-
- #include "dino.h"
-
- #define M 12
- #define N 12
- #define P1 4
- #define P2 4
-
- environment node[P1:id1][P2:id2] {
-
- #include "../inc/map.c"
-
- /* ==> A listing of this file appears after
- after example 2.4. */
-
- map LeftUpOverlap = [block overlap 1,0][block overlap 1,0];
-
- /* ==> This is a user-defined mapping. It
- sets up a mapping which divides a 2D
- array into blocks, and each environment
- receives a copy of the one element
- border strips to the west and north. */
-
- composite smooth (a, in iter)
-
- double distributed a[M][N] map LeftUpOverlap;
- int iter;
-
- {
- int i, j, k; /* Looping variables */
- map_var a1, a2; /* Mapping variables */
-
- /* Setup the mapping variables */
- set_map_var (M, P1, id1, 1, 0, &a1);
- set_map_var (N, P2, id2, 1, 0, &a2);
- limit_map_var (1, M-1, &a1);
- limit_map_var (1, N-1, &a2);
-
- /* Repeat the smoothing process iter times */
- for (k = 0; k < iter; k++) {
-
- /* Send out your data and receive it back again, if not the first
- * iteration */
- if (k != 0) {
-
- if (id1 != P1-1 || id2 != P2-1)
- a[<a1.left,a1.right>][<a2.left,a2.right>]# =
- a[<a1.left,a1.right>][<a2.left,a2.right>];
-
- /* ==> The lower right environment has no
- data to send. This if statement
- prevents a run-time warning about it. */
-
- if (id1 != 0 || id2 != 0)
- a[<a1.lover,a1.rover>][<a2.lover,a2.rover>]#;
-
- /* ==> The upper left environment has no
- data to receive. This if statement
- prevents a run-time warning about it. */
-
- }
-
- /* Perform the computation, but only on non-edge nodes */
- for (i = a1.left; i <= a1.right; i++)
- for (j = a2.left; j <= a2.right; j++)
- a[i][j] = a[i-1][j] + a[i][j-1];
-
- }
- }
- }
-
- environment host {
-
- void main ()
-
- {
- double a[M][N]; /* Input data */
- int iter; /* Holds the iteration count */
-
- int i, j; /* Looping variables */
-
- /* Set up the initial data for a[][] */
- for (i = 0; i < M; i++)
- for (j = 0; j < N; j++)
- a[i][j] = 0;
- for (i = 0; i < M; i++)
- a[i][0] = 1;
- for (j = 0; j < N; j++)
- a[0][j] = 1;
-
- /* Set up the variable which will contain the number of iterations */
- iter = 7;
-
- /* Print out the initial data */
- printf ("Initial data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%7.1f", a[i][j]);
- printf ("\n");
- }
-
- /* Perform the computation */
- smooth (a[][], iter)#;
-
- /* Printout the results */
- printf ("Result data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%5.1f", a[i][j]);
- printf ("\n");
- }
- }
- }
-